package com.augurit.wf.app.doccode.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.base.extmodel.BasicCombo;
import com.augurit.wf.app.doccode.web.form.OaDocCodeForm;
import com.augurit.wf.common.entity.OaDocCode;

public class OaDocCodeConvertor {
	public static OaDocCodeForm convertVoToForm(OaDocCode entity) {
		if(entity != null) {
			OaDocCodeForm form = new OaDocCodeForm();
			form.setId(entity.getId());
			form.setTemplate(entity.getTemplate());
			form.setWord(entity.getWord());
			form.setYear(entity.getYear());
			form.setSeq(entity.getSeq());
			form.setUnit(entity.getUnit());
			form.setLeakNo(entity.getLeakNo());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(OaDocCodeForm form, OaDocCode entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getTemplate() != null && form.getTemplate().trim().length() > 0)
				entity.setTemplate(form.getTemplate().trim());
			if(form.getWord() != null && form.getWord().trim().length() > 0)
				entity.setWord(form.getWord().trim());
			if(form.getYear() != null && form.getYear().trim().length() > 0)
				entity.setYear(form.getYear().trim());
			entity.setSeq(form.getSeq());
			if(form.getUnit() != null && form.getUnit().trim().length() > 0)
				entity.setUnit(form.getUnit().trim());
			if(form.getLeakNo() != null && form.getLeakNo().trim().length() > 0)
				entity.setLeakNo(form.getLeakNo().trim());
		}
	}
	
	public static List<OaDocCodeForm> convertVoListToFormList(List<OaDocCode> oaDocCodeList) {
		if(oaDocCodeList != null && oaDocCodeList.size() > 0) {
			List<OaDocCodeForm> oaDocCodeFormList = new ArrayList();
			for(int i=0; i<oaDocCodeList.size(); i++) {
				oaDocCodeFormList.add(convertVoToForm(oaDocCodeList.get(i)));
			}
			return oaDocCodeFormList;
		}
		return null;
	}

	public static List<OaDocCode> convertFormListToVoList(List<OaDocCodeForm> oaDocCodeFormList) {
		if(oaDocCodeFormList != null && oaDocCodeFormList.size() > 0) {
			List<OaDocCode> oaDocCodeList = new ArrayList();
			for(int i=0; i<oaDocCodeFormList.size(); i++) {
				OaDocCode oaDocCode = new OaDocCode();
				convertFormToVo(oaDocCodeFormList.get(i), oaDocCode);
				oaDocCodeList.add(oaDocCode);
			}
			return oaDocCodeList;
		}
		return null;
	}
	
	public static List<BasicCombo> convertToComboList(List<OaDocCode>codeList){
		List<BasicCombo> result = null;
		if(codeList != null && codeList.size()>0){
			result = new ArrayList<BasicCombo>();
			
			
			for(OaDocCode entity:codeList){
				BasicCombo combo = new BasicCombo();
				Long newSeq = entity.getSeq() +1L;
				
				combo.setLabel(entity.getWord() +entity.getYear() +newSeq +entity.getUnit());
				combo.setValue(entity.getId().toString());
				
				result.add(combo);
			}
		}
		
		return result;
	}
}